﻿/*
Digraph (library for building, traversal, comparison and saving of directed
graph).

Copyright (C) 2014 Dmitry Merzagitovich Arslanov

This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option) any
later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*/

// How to traverse digraph.

namespace CustomTypes2
{
    public class Door
    {
        public string Nameboard;

        public bool IsLocked;

        public Door(string nameboard, bool isLocked)
        {
            Nameboard = nameboard;
            IsLocked = isLocked;
        }
    }

    public class Corridor
    {
        public double Length;
    }
}

namespace Sample7
{
    using CustomTypes2;
    using System;

    using Builder = Digraph.Builder<CustomTypes2.Door, CustomTypes2.Corridor>;
    using Vertex = Digraph.Vertex<CustomTypes2.Door, CustomTypes2.Corridor>;

    public static class App
    {
        public static void Main()
        {
            Builder builder = new Builder();
            Vertex v1 = builder.NewVertex(new Door("1", false));
            Vertex v2 = builder.NewVertex(new Door("2", true));
            Vertex v3 = builder.NewVertex(new Door("3", false));
            Vertex v4 = builder.NewVertex(new Door("4", false));
            Vertex v5 = builder.NewVertex(new Door("5", false));
            Vertex v6 = builder.NewVertex(new Door("6", true));
            Vertex v7 = builder.NewVertex(new Door("7", false));
            builder.NewArc(v1, v2);
            builder.NewArc(v1, v3);
            builder.NewArc(v2, v4);
            builder.NewArc(v2, v5);
            builder.NewArc(v3, v6);
            builder.NewArc(v3, v7);
            // Step through unlocked doors.
            builder.Digraph.Traverse(v1, Digraph.Direction.Forward,
                // Lambda to select vertex.
                (sel, cur) => cur.Content.IsLocked ? sel : cur,
                // Lambda to process selected vertex.
                v =>
                {
                    if (v != null) Console.WriteLine(v.Content.Nameboard);
                    else Console.WriteLine("End of traversal.");
                });
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
    }
}

#region Program output is shown below in comments
/*
3
7
End of traversal.
Press any key to exit...
*/
#endregion
